package com.ruoyi.laiqianba.service.impl;

import cn.hutool.core.util.StrUtil;
import com.ruoyi.laiqianba.constant.RedisKeyConstant;
import com.ruoyi.laiqianba.service.IHandleCacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class HandleCacheServiceImpl implements IHandleCacheService {

    @Autowired
    RedisTemplate redisTemplate;

    @Override
    public void clearChannelCache(String channelCode){
        String redisKey = StrUtil.format(RedisKeyConstant.CHANNEL_CACHE_KEY, channelCode);
        redisTemplate.delete(redisKey);
    }

    @Override
    public void clearProductCache(String productId) {
        String redisKey = StrUtil.format(RedisKeyConstant.PRODUCT_CACHE_KEY, productId);
        redisTemplate.delete(redisKey);
    }

    @Override
    public void clearSourceDictByParentId(String parentId) {
        String redisKey = StrUtil.format(RedisKeyConstant.SOURCE_DICT_INFO, parentId);
        redisTemplate.delete(redisKey);
    }

    @Override
    public void clearProductRemainNumber(String productId, String nowDate) {
        String redisKey = StrUtil.format(RedisKeyConstant.PRODUCT_UV_REMAIN_COUNT_KEY, nowDate, productId);
        redisTemplate.delete(redisKey);
    }

    @Override
    public void clearSourceBaseInfo(String channelCode) {
        String redisKey = StrUtil.format(RedisKeyConstant.SOURCE_BASE_INFO_KEY, channelCode);
        redisTemplate.delete(redisKey);
    }

    @Override
    public void clearMerchantBaseInfo(Long infoId) {
        String redisKey = StrUtil.format(RedisKeyConstant.MERCHANT_BASE_INFO_KEY, infoId);
        redisTemplate.delete(redisKey);
    }

}


